/**
 * changes I had to make for this to work...
 * 
 * in Game.java added   Player.setCurrentHealth(Player.getPoisonReceived().poisonTarget(Player.getCurrentHealth())); at line 154
 * in EnemyList.java   enemy.setCurrentHealth(enemy.poisonReceived.poisonTarget(enemy.getCurrentHealth())); at line 55
 * in Enemy.java          protected Poison poisonReceived = new Poison();
 * 							and
 * 							public void setPoisonReceived(Poison poison)
						    {
						    	this.poisonReceived=poison;
						    	System.out.println("newpoison");
						    }
 * in Collision.java   added    bullet.enemyOnHit(enemy); at line 40  and                         bullet.playerOnHit(); at line 60		
 * in Player.java added  private static Poison poisonReceived = new Poison(), getter, and setter		
 * 
 * added PoisonBullet subclass
 * onEnemyHit() onPlayerHit() methods in Bullet class can be used to apply slows to a target too.   
 */


package edu.csumb.itcd.teammario;

public class Poison {

	private int poisonDamage;
	private int poisonDuration;
	private int lastPoisonTime;
	private boolean currentlyPoisoned = false;
	private int infectionCount = 0;
	private int infectionMax = 10;



	public Poison()
	{
		poisonDamage=0;
		poisonDuration=0;
		infectionCount = 1;

	}
	
	public Poison(int poisonDamage, int poisonDuration)
	{
		this.poisonDamage=poisonDamage;
		this.poisonDuration=poisonDuration;
	}

	//if the amount of poison damage and duration is greater a new poison is applied
	public void setPoison(int poisonDamage, int poisonDuration){
		if((poisonDamage >= this.poisonDamage)&&(poisonDuration>=this.poisonDuration))
		{
			setPoisonDamage(poisonDamage);
			setPoisonDuration(poisonDuration);
		}
	}
	public int getPoisonDamage() {
		return poisonDamage;
	}
	
	public int getInfectionCount() {
		return infectionCount;
	}

	public void setInfectionCount(int infectionCount) {
		this.infectionCount = infectionCount;
	}
	public int getInfectionMax() {
		return infectionMax;
	}

	public void setInfectionMax(int infectionMax) {
		this.infectionMax = infectionMax;
	}

	public boolean isCurrentlyPoisoned() {
		return currentlyPoisoned;
	}

	public void setPoisonDamage(int poisonDamage) {
		this.poisonDamage = poisonDamage;
	}

	public int getPoisonDuration() {
		return poisonDuration;
	}

	public void setPoisonDuration(int poisonDuration) {
		this.poisonDuration = poisonDuration;
	}
	// Poison damage is applied every 10 ticks and 1 duration is subtracted
	public int poisonTarget(int targetCurrentHealth)
	{
		if (Game.gameCount >= lastPoisonTime)
		{
			//System.out.println("applying poison");
			lastPoisonTime=Game.gameCount+10;
			//System.out.println(targetCurrentHealth);
			targetCurrentHealth-=poisonDamage;
			//System.out.println(targetCurrentHealth);
			poisonDuration--;
			currentlyPoisoned = true;
			if(poisonDuration<=0)
			{
				currentlyPoisoned = false;
				poisonDamage=0;
			}
			return targetCurrentHealth;
		}
		// poison not applied, health remains the same
		else
		{
			return targetCurrentHealth;
		}
	}
	
}
